-
Notifications
You must be signed in to change notification settings - Fork 1k
Added setXXX methods to change used pins of an instance #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
That change seems very helpful but it there any mechanism to check if the selected pin has the right capability? |
Pins capabilities are checked during the
For I2C: Arduino_Core_STM32/cores/arduino/stm32/twi.c Line 166 in cf03b78
Unfortunately the standard API Note: Init check also that all pins are linked to the same peripheral. |
Yes I would agree to @romainreignier .. For example in my case I needed to set the SDA SCL pins to A4,A5.. But I am not able to do that.. Because I am using IKSA102 board for temperature,Humidity,Pressure sensing which uses I2C and is probably using either of A4,A5.. Hence when I set SDA SCL pins to A4,A5 ,I am getting wrong values for Temperature and Humidity.. |
@mayukhIITD |
@fpistm Ah, that's great that the pins are being checked but it is at runtime and the user need a serial console opened, right? It would be nice to check at compile time with static_assert but will prevent to change the pins on the fly :( |
Yes, right. |
Ok, I see. But anyway, this change is great and will ease the usage of these peripherals 👍 |
I was playing around with compile-time checks on Wire.setSDA() and Wire.SDL(), this is what I came up with: Wire.h:
variant.h:
The.ino
This would require some work to manually edit each variant.h (add the I2C & SPI constexpr functions) Disclamer: I've only tested that it compiles |
Nice code snippets ;)
anyway, User has to know which pins are used for the wiring of it's I2C device. |
agree with @fpistm - compile time check looks a bit overkill to me. What really matters is that user correctly check schematics and wiring of the hardware board - that's usually were most encountered errors comes from ... |
Example to change pins used by Wire instance (by default use defined SDA/SCL ): Wire.setSDA(A4); Wire.setSCL(PC2); Wire.begin(); Example to change pins used by SPI instance (by default use defined MISO/MOSI/SCK): SPI.setMOSI(22); SPI.setMISO(PA3); SPI.begin(); Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
Added setXXX methods to change used pins of an instance
Example to change pins used by Wire instance (by default use defined SDA/SCL ):
Example to change pins used by SPI instance (by default use defined MISO/MOSI/SCK):